﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VINETLIFE.DO;
using VINETLIFE.BL;
using System.Web.UI.HtmlControls;
using System.Data;

namespace VINETLIFE
{
    public partial class AlbumDetail : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            LoadAlbum();
            if (!string.IsNullOrEmpty(Request.QueryString["ID"]))
            {
                if (!IsPostBack)
                {
                    int AlbumID = int.Parse(Request.QueryString["ID"].ToString());
                    rptImagesDataSource(AlbumID);

                    cmsAlbumDO objAlbum = new cmsAlbumBL().Select(new cmsAlbumDO() { AlbumID = AlbumID });
                    Page.Title = objAlbum.Title + " | " + Ultility.WebTitle();

                    sysConfigDO objConfig = new sysConfigDO();
                    objConfig.ConfigID = 2;

                    objConfig = new sysConfigBL().Select(objConfig);


                    HtmlMeta metaKey = new HtmlMeta();
                    metaKey.Name = "keywords";
                    metaKey.Content = objConfig.ConfigValue;
                    Page.Header.Controls.Add(metaKey);


                    HtmlMeta metaDesc = new HtmlMeta();
                    metaDesc.Name = "description";
                    metaDesc.Content = objAlbum.Description;
                    Page.Header.Controls.Add(metaDesc);

                    
                }
            }
            else
            {
                Response.Redirect("/thu-vien-anh/");
            }
        }

        private void rptImagesDataSource(int albumID)
        {
            DataTable dtSource = new MediaBL().GetByAlbum(albumID);
            rptMainImage.DataSource = rptThumbnail.DataSource = dtSource;
            rptMainImage.DataBind();
            rptThumbnail.DataBind();
        }

        void LoadAlbum()
        {
            DataTable dtGallery = new cmsAlbumBL().GetByTopType(10, true);
            rplistGallery.DataSource = dtGallery;
            rplistGallery.DataBind();

            DataTable dtVideo = new cmsAlbumBL().GetByTopType(10, false);
            rpListVideo.DataSource = dtVideo;
            rpListVideo.DataBind();
        }

        public string Change_AV(string s)
        {
            return Ultility.Change_AV(s);
        }
    }
}